package cn.kz.hrm.fallbackfactory;

import cn.kz.hrm.commonfeiclient.CommonFeignClient;
import cn.kz.hrm.doc.CourseDoc;
import cn.kz.hrm.query.CourseQuery;
import cn.kz.hrm.util.AjaxResult;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component //交给spring进行管理
public class CommonFeignClientFallbackFactory implements FallbackFactory<CommonFeignClient>{

    private Logger logger = LoggerFactory.getLogger(CommonFeignClientFallbackFactory.class);

    @Override
    public CommonFeignClient create(Throwable throwable) {
        return new CommonFeignClient(){

            //设置redis的降级方法
            @Override
            public AjaxResult setRedis(String key, String value) {
                throwable.printStackTrace();
                logger.error("添加redis失败！！");
                return AjaxResult.me().setSuccess(false).setMessage("添加redis失败！！！");
            }

            //获取redis的降级方法
            @Override
            public AjaxResult getRedis(String key) {
                throwable.printStackTrace();
                logger.error("获取redis失败！！");
                return AjaxResult.me().setSuccess(false).setMessage("获取redis失败！！！");
            }

            @Override
            public AjaxResult setRedisOutTime(String key, int time, String value) {
                throwable.printStackTrace();
                logger.error("添加带过期时间的redis失败！！");
                return AjaxResult.me().setSuccess(false).setMessage("添加带过期时间的redis失败！！！");
            }

            @Override
            public AjaxResult deleteRedis(String key) {
                throwable.printStackTrace();
                logger.error("删除redis失败！！");
                return AjaxResult.me().setSuccess(false).setMessage("删除redis失败！！！");
            }

            @Override
            public AjaxResult saveElasticReseach(CourseDoc courseDoc) {
                throwable.printStackTrace();
                logger.error("存储ElasticReseach失败！！");
                return AjaxResult.me().setSuccess(false).setMessage("存储ElasticReseach失败！！");
            }

            @Override
            public AjaxResult deleteElasticReseach(long id) {
                throwable.printStackTrace();
                logger.error("删除ElasticReseach失败！！");
                return AjaxResult.me().setSuccess(false).setMessage("删除ElasticReseach失败！！");
            }

            @Override
            public AjaxResult getQueryCourses(CourseQuery courseQuery) {
                throwable.printStackTrace();
                logger.error("从ElasticReseach查询课程失败！！");
                return AjaxResult.me().setSuccess(false).setMessage("从ElasticReseach查询课程失败！！");
            }
        };
    }
}
